if(typeof Ext.user.method.binzhongidstore == 'undefined'){ Ext.user.method.binzhongidstore = Ext.user.method.binzhongid('/Department/data/'); }
if(typeof Ext.user.method.cityidstore == 'undefined'){ Ext.user.method.cityidstore = Ext.user.method.cityid('/Department/data/'); }
Ext.user.departmenttree = Ext.extend(Ext.tree.TreePanel, {
    title: '部门',
	id:'departmenttree',
    width: 700,
    height: 600,
	style:'margin:0 auto;',
	renderTo:'department_index',
    initComponent: function() {
        this.root = {
            text: '网络部',
            id: 'menu'
        };
        this.loader = {
            url: Ext.user.baseUrl + '/Department/data/',
            nodeParameter: 'p',
			baseParams:{do:'p'}
        };
		this.tbar = [{text: '添加部门',iconCls: 'page_add',
			handler:function(){
				var tree = new Ext.user.departmentWindows();
				tree.show();
				
			},
		}];
		this.listeners= {
			click:function(n,e){
				var tree = new Ext.user.departmentWindows({edit:{id:n.attributes.did}});
				tree.show();
				tree.setTitle('修改信息');
				
				
                Ext.user.method.loaddataForm({
					url:'/Department/data/',
					params:{where:n.attributes.did,do:'treeid'},
					Formid:'departmentForm',
					method:'POST',
					recorddata:[{name: 'name', type: 'string'}, 'did','sort','tel','intro','cityid','binzhongid']
				});
					Ext.getCmp('departmentForm').add(new Ext.form.Hidden({name:'did',value:n.attributes.did,renderTo:'departmentFormid'}));
			},
	
		};
        Ext.user.departmenttree.superclass.initComponent.call(this);
    }
});
Ext.user.departmentWindows = Ext.extend(Ext.Window, {
    title: '添加部门',
    width: 500,
    border: false,
    frame: true,
	modal:true,
	modal:true,
	id:'departmenttreeWindow',
	listeners:{
		close:function(a){
				Ext.user.centermenu.setDisabled(false);
			  }
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		Ext.apply(this,this.cfg);
        this.items = [
            {
                xtype: 'form',
				id:'departmentForm',
				formId:'departmentFormid',
                border: false,
                items: [
                    {
                        xtype: 'fieldset',
                        title: '必填信息',
                        style: 'margin: 0 auto;',
                        width: 480,
                        items: [
                            {
                                xtype: 'textfield',
                                fieldLabel: '部门名称',
                                anchor: '50%',
                                width: 300,
                                name: 'name'
                            },
                            {
                                xtype: 'combo',
                                fieldLabel: '病种',
                                anchor: '50%',
                                width: 300,
                                name: 'binzhongid',
								store: Ext.user.method.binzhongidstore,
								displayField:'name',
								valueField:'id',
								hiddenName:'binzhongid',
								hiddenValue:'0',
								editable:false,
								typeAhead: true,
								forceSelection: true,
								mode: 'local',
								triggerAction: 'all',
								selectOnFocus:true
                            },
                            {
                                xtype: 'combo',
                                fieldLabel: '地区',
                                anchor: '50%',
                                width: 300,
                                name: 'cityid',
								store: Ext.user.method.cityidstore,
								displayField:'name',
								valueField:'id',
								hiddenName:'cityid',
								hiddenValue:'0',
								editable:false,
								typeAhead: true,
								forceSelection: true,
								mode: 'local',
								triggerAction: 'all',
								selectOnFocus:true
                            },
                            {
                                xtype: 'textfield',
                                fieldLabel: '排序',
                                anchor: '50%',
                                width: 300,
                                name: 'sort',
                                value: 0
                            }
                        ]
                    },
                    {
                        xtype: 'fieldset',
                        title: '选填信息',
                        style: 'margin: 0 auto;margin-bottom:5px;',
                        width: 480,
                        items: [
                            {
                                xtype: 'textfield',
                                fieldLabel: '部门电话',
                                anchor: '50%',
                                width: 300,
                                name: 'tel',
                                emptyText: '格式:0971-0000000'
                            },
                            {
                                xtype: 'textfield',
                                fieldLabel: '电子邮箱',
                                anchor: '50%',
                                width: 300,
                                name: 'email'
                            },
                            {
                                xtype: 'textarea',
                                anchor: '90%',
								name: 'intro',
                                fieldLabel: '简介'
                            }
                        ]
                    }
                ]
            }
        ];
		if(typeof this.edit == 'undefined'){
			this.buttons = [{text:'添加',
				handler:function(){
					Ext.getCmp('departmentForm').form.submit({
						method: 'POST',
						url:Ext.user.baseUrl + '/Department/add',
						waitMsg: '正在提交。。。',
						success:function(f,a){
							Ext.MessageBox.show({
								 title: '警告',
								 msg: a.result.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
							Ext.getCmp('departmenttree').root.reload();
							Ext.getCmp('departmenttreeWindow').close();
						},
						failure:function(f,a){
								Ext.MessageBox.show({
									 title: '警告',
									 msg: a.result.info,
									 buttons: Ext.MessageBox.OK,
										 icon:'ext-mb-error',
								});	
						}
					});
				}
			},{text:'重置',
				handler:function(){
					Ext.getCmp('departmentForm').form.reset();
				}
			}];
		}else{
			this.buttons = [{text:'修改',
				handler:function(){
					Ext.getCmp('departmentForm').form.submit({
						method: 'POST',
						url:Ext.user.baseUrl + '/Department/edit/',
						waitMsg: '正在提交。。。',
						success:function(f,a){
							Ext.MessageBox.show({
								 title: '警告',
								 msg: a.result.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
							Ext.getCmp('departmenttree').root.reload();
							Ext.getCmp('departmenttreeWindow').close();
						},
						failure:function(f,a){
								Ext.MessageBox.show({
									 title: '警告',
									 msg: a.result.info,
									 buttons: Ext.MessageBox.OK,
										 icon:'ext-mb-error',
								});	
						}
					});
				}
			},{text:'删除',
				handler:function(){
					Ext.Ajax.request({
					   url: Ext.user.baseUrl + '/Department/delete',
					   method:'POST',
					   callback:function(o,s,r){
							var data = Ext.util.JSON.decode(r.responseText);
							Ext.MessageBox.show({
								 title: '警告',
								 msg: data.info,
								 buttons: Ext.MessageBox.OK,
								 icon:'ext-mb-info',
							});
						
							Ext.getCmp('departmenttree').root.reload();
					   },
					   params: {id:Ext.getCmp('departmenttreeWindow').edit.id}
					});
					Ext.getCmp('departmenttreeWindow').close();
				}
			}];		
		
		}
        Ext.user.departmentWindows.superclass.initComponent.call(this);
    }
});





